/*
 * Copyright (C) 2011-2013 Eric Lasota
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
#ifndef __RDX_GFG_H__
#define __RDX_GFG_H__

#include "rdx_pragmas.hpp"
#include "rdx_platform.hpp"
#include "rdx_basictypes.hpp"

#ifdef RDX_BUILD_DYNLIB
#	define RDX_DYNLIB_API RDX_DYNLIB_EXPORT
#else
#	define RDX_DYNLIB_API RDX_DYNLIB_IMPORT
#endif

namespace RDX
{
	void Initialize();

	struct OperationContext;

	namespace ObjectManagement
	{
		struct Allocator;
		struct IObjectManager;
		struct INativeTypeHost;
	}

	namespace Programmability
	{
		struct ICodeProvider;
		struct RuntimeTrace;
		class PrecompiledCodeModule;
		class String;
		struct Journal;
		class JournalScanState;
		struct RuntimeStackFrame;
		union RuntimeStackValue;
	}
}



RDX_DYNLIB_API void RDX_Initialize();
RDX_DYNLIB_API ::RDX::ObjectManagement::IObjectManager *RDX_CreateObjectManager(const ::RDX::ObjectManagement::Allocator *alloc, const ::RDX::ObjectManagement::INativeTypeHost *nth, const ::RDX::Programmability::ICodeProvider *cp);
RDX_DYNLIB_API ::RDX::Programmability::ICodeProvider *RDX_CreateInterpreterCodeProvider(const ::RDX::ObjectManagement::Allocator *alloc, const ::RDX::Programmability::PrecompiledCodeModule **modules, ::RDX::LargeInt numModules);

RDX_DYNLIB_API const RDX::ObjectManagement::INativeTypeHost *RDX_GetNumericTypesPlugin();

RDX_DYNLIB_API int RDX_RuntimeTrace_TraceParent(const ::RDX::Programmability::RuntimeTrace *trace, ::RDX::Programmability::RuntimeTrace *outTrace);
RDX_DYNLIB_API ::RDX::LargeInt RDX_RuntimeTrace_NumJournalEntries(const ::RDX::Programmability::RuntimeTrace *trace);
RDX_DYNLIB_API void RDX_RuntimeTrace_JournalEntry(const ::RDX::Programmability::RuntimeTrace *trace, ::RDX::LargeInt index, ::RDX::Programmability::Journal *outJournal);
RDX_DYNLIB_API void RDX_RuntimeTrace_ScanJournals(const ::RDX::Programmability::RuntimeTrace *trace, ::RDX::Programmability::JournalScanState *outJournalScanState);
RDX_DYNLIB_API void RDX_RuntimeTrace_GetFileNameAndLineNumber(const ::RDX::Programmability::RuntimeTrace *trace, const ::RDX::Programmability::String **outFilename, ::RDX::LargeInt *outLineNumber);

RDX_DYNLIB_API void RDX_JournalScanState_NextJournal(::RDX::Programmability::JournalScanState *jss, ::RDX::Programmability::Journal *outJournal);

RDX_DYNLIB_API void RDX_ExportSource(::RDX::ObjectManagement::IObjectManager *objm, void *stdFile, int domain);


RDX_DYNLIB_API void *RDX_RuntimeUtilities_ArrayIndex(void *o, const ::RDX::Programmability::RuntimeStackValue *rsv);
RDX_DYNLIB_API void *RDX_RuntimeUtilities_NewObjectInstance(::RDX::OperationContext *ctx, ::RDX::ObjectManagement::IObjectManager *objm,
	const ::RDX::Programmability::Type *t, const ::RDX::Programmability::RuntimeStackValue *dimensions, ::RDX::LargeInt numDimensions);
RDX_DYNLIB_API int RDX_RuntimeUtilities_ExpandFrame(void *stackBase, void *frameBase, ::RDX::LargeInt stackSize, ::RDX::Programmability::RuntimeStackFrame **newBP, int hasInsertionPoint, int hasNativeFrame);
RDX_DYNLIB_API int RDX_RuntimeUtilities_EnterMethodInline(::RDX::ObjectManagement::IObjectManager *objm, const ::RDX::Programmability::Method *m, ::RDX::Programmability::RuntimeStackFrame *currentFrame,
	void *frameBase, void *stackBase, ::RDX::Programmability::RuntimeStackValue *prv, ::RDX::Programmability::RuntimeStackFrame *newFrame);
RDX_DYNLIB_API int RDX_RuntimeUtilities_EnterMethodRoot(::RDX::ObjectManagement::IObjectManager *objm, const ::RDX::Programmability::Method *m, ::RDX::Programmability::RuntimeStackFrame *currentFrame, void *frameBase, void *stackBase,
	::RDX::Programmability::RuntimeStackValue *prv, ::RDX::Programmability::RuntimeStackFrame *newFrame, void *recordedInsertionPoint, int throughNative, const ::RDX::Programmability::Method *viaMethod, const ::RDX::Programmability::RuntimeStackFrame *subFrame);

#endif
